package com.ktjiaoyu.ktmall.dao.impl;

import com.ktjiaoyu.ktmall.dao.BaseDao;
import com.ktjiaoyu.ktmall.dao.CategoryDao;
import com.ktjiaoyu.ktmall.entity.Category;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class CategoryDaoImpl extends BaseDao implements CategoryDao {
    @Override
    public List<Category> findAll() {
        String sql = "select * from kt_category where is_delete = 0 order by parent_id,sort asc;";
        try {
            return executeQuery(sql,rs->{
                List<Category> list = new ArrayList<>();
                try {
                    while (rs.next()){
                        list.add(extractCategory(rs));
                    }
                }catch (SQLException e){
                    e.printStackTrace();
                }
                return list;
            });
        }catch (SQLException e){
            e.printStackTrace();
            return new ArrayList<>();
        }
    }
}
